package com.huishu.tcm.service.serviceImpl;

import com.huishu.tcm.entity.User;
import com.huishu.tcm.mapper.UserMapper;
import org.springframework.stereotype.Service;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huishu.tcm.service.UserService;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

	 /**
     * 筛选条件
     * @param v
     * @return
     */
    @Override
    public QueryWrapper<User> getQueryWrapper(User v){
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        if(ObjectUtil.isEmpty(v)){
            return queryWrapper;
        }
		if(ObjectUtil.isNotEmpty(v.getId())){
        	queryWrapper.eq("id", v.getId());
        }
		// 用户角色
		if(ObjectUtil.isNotEmpty(v.getRole())){
		    queryWrapper.eq("role",v.getRole());
        }
		// 用户注册状态
		if(ObjectUtil.isNotEmpty(v.getRegisterStatus())){
		    queryWrapper.eq("register_status",v.getRegisterStatus());
        }
		// 基层医疗机构id
        if(ObjectUtil.isNotEmpty(v.getInstitutionId())){
            queryWrapper.eq("institution_id",v.getInstitutionId());
        }
        // 是否已经结束管理
        if(ObjectUtil.isNotEmpty(v.getEndManagement())){
            if(v.getEndManagement()){
                queryWrapper.eq("end_management", true);
            }else{
                queryWrapper.ne("end_management", true);
            }
        }
       	return queryWrapper;
    }
}